package org.wwb.antbox.center.web.controller.sys.role;

import org.ant.commons.models.model.BaseIdModel;
import org.ant.commons.models.result.BaseEditResult;
import org.ant.commons.models.result.BaseListResult;
import org.ant.commons.models.result.BasePageResult;
import org.ant.commons.models.result.BaseResult;
import org.springframework.web.bind.annotation.*;
import org.wwb.antbox.center.web.Router;
import org.wwb.antbox.user.iservice.ServiceUserTool;
import org.wwb.antbox.user.model.role.model.SysRoleAddModel;
import org.wwb.antbox.user.model.role.model.SysRoleDelModel;
import org.wwb.antbox.user.model.role.model.SysRoleEditModel;
import org.wwb.antbox.user.model.role.model.SysRolePageModel;
import org.wwb.antbox.user.model.role.view.RoleListView;
import org.wwb.antbox.user.model.role.view.SysRolePageView;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author Bond
 * @Date: 2020-02-07 10:50:34
 * @Description: 系统角色控制器
 */
@RestController
public class SysRoleController {
    /**
     * 获取系统角色分页列表
     * @param sysRolePageModel
     * @return BasePageResult<SysRolePageView>
     */
    @PostMapping(value = Router.SysRole.GET_SYS_ROLE_PAGE)
    public BasePageResult<SysRolePageView> getSysRolePage(@RequestBody @Valid SysRolePageModel sysRolePageModel){
        return ServiceUserTool.sysRoleService().getSysRolePage(sysRolePageModel);
    }

    /**
     * 添加系统角色
     * @param sysRoleAddModel
     * @return BasePageResult<Integer>
     */
    @PostMapping(value = Router.SysRole.SAVE_SYS_ROLE)
    public BaseResult<String> saveSysRole(@RequestBody @Valid SysRoleAddModel sysRoleAddModel){
        return ServiceUserTool.sysRoleService().saveSysRole(sysRoleAddModel);
    }

    /**
     * 删除系统角色
     * @param sysRoleDelModel
     * @return BaseResult<Integer>
     */
    @PostMapping(value = Router.SysRole.DEL_SYS_ROLE)
    public BaseResult<Integer> delSysRole(@RequestBody @Valid SysRoleDelModel sysRoleDelModel){
        return ServiceUserTool.sysRoleService().delSysRole(sysRoleDelModel);
    }

    /**
     * 停用系统角色
     * @param sysRoleDelModel
     * @return BaseResult<Integer>
     */
    @PostMapping(value = Router.SysRole.DISABLE_SYS_ROLE)
    public BaseResult<Integer> disableSysRole(@RequestBody @Valid SysRoleDelModel sysRoleDelModel){
        return ServiceUserTool.sysRoleService().disableSysRole(sysRoleDelModel);
    }

    /**
     * 启用系统角色
     * @param sysRoleDelModel
     * @return BaseResult<Integer>
     */
    @PostMapping(value = Router.SysRole.ENABLE_SYS_ROLE)
    public BaseResult<Integer> enableSysRole(@RequestBody @Valid SysRoleDelModel sysRoleDelModel){
        return ServiceUserTool.sysRoleService().enableSysRole(sysRoleDelModel);
    }

    /**
     * 跳转修改系统角色
     * @param id id
     * @return BaseEditResult
     */
    @GetMapping(value = Router.SysRole.DO_EDIT_SYS_ROLE)
    public BaseEditResult doEditSysRole(@RequestParam("id") Integer id){
        return ServiceUserTool.sysRoleService().doEditSysRole(new BaseIdModel(id));
    }

    /**
     * 修改系统角色
     * @param sysRoleEditModel
     * @return BaseResult<Integer>
     */
    @PostMapping(value = Router.SysRole.EDIT_SYS_ROLE)
    public BaseResult<Integer> editSysRole(@RequestBody @Valid SysRoleEditModel sysRoleEditModel){
        return ServiceUserTool.sysRoleService().editSysRole(sysRoleEditModel);
    }


    /**
     * 获取角色已拥有菜单Id集合
     * @param roleId 角色Id
     * @return BaseResult<List<String>> 菜单Id集合
     */
    @GetMapping(value = Router.SysRole.GET_ROLE_MENU_ID_LIST)
    public BaseResult<List<String>> getRoleMenuIdList(@RequestParam("roleId") String roleId){
        return ServiceUserTool.sysRoleMenuService().getRoleMenuIdList(roleId);
    }


    /**
     * 获取系统角色列表  用于用户角色授权时的穿梭框
     * @return
     */
    @GetMapping(value = Router.SysRole.GET_SYS_ROLE_LIST_4_TRANSFER)
    public BaseListResult<RoleListView> getSysRoleList4Transfer(){
        return ServiceUserTool.sysRoleService().getSysRoleList4Transfer();
    }

}
